const { UserWantbuy } = require("../../../Models");
class WantbuyController {

  async index({ request, response, params }) {
    let query = UserWantbuy.query()
    const { adminUser } = request
    let {
      page = 1,
      pageSize = 10,
      productName,
      exhibitorName
    } = request.get()
    if (exhibitorName) {
      exhibitorName = decodeURI(exhibitorName.trim())
      if (exhibitorName) query.whereRaw(`exhibitorName like ?`, `%${exhibitorName}%`)
    }
    if (productName) {
      productName = decodeURI(productName.trim())
      if (productName) query.whereRaw(`productName like ?`, `${productName}`)
    }
    // console.log(adminUser, 'adminUser')
    if (adminUser.exhibitorID != 0) {
      query.where('exhibitorID', '=', adminUser.exhibitorID)
    }
    const list = await query.paginate(page, pageSize)
    response.json({ error: 0, data: list })
  }
}
module.exports = WantbuyController